<template>
	<view class="mainpadding block" v-if="pageShow">
		<view class="ffffff radius">
			<view class="lanbox flexbetween">
				<view class="">
					<view class="strongtext fonweight xiaobai">我的金币</view>
					<view class=" fonweight xiaobai" style="font-size: 70rpx;">{{userInfo.jb_num}}</view>
				</view>
				<view class="baibtn1 flexcenter" v-if="!isSH" @click="tztx">去提现</view>
			</view>
			<view class="" style="padding: 42rpx 30rpx;">
				<view class="xiaohui strongtext fonweight">金币充值</view>
				<view class="flexleft flex_wrap">
					<view class="flexcenter sanshis margin_top2" v-for="item in jbItemList" :key="item.id" @click="jb_item_id=item.id;payprice=item.price;product_id=item.product_id;">
						<view class="flexcolumn" style="width: 190rpx;padding: 30rpx 0;" :class="item.id==jb_item_id?'borders':'border'">
							<view class="flexleft">
								<image class="jinbi margin_right1" src="../static/image/system/jb.png" mode=""></image>
								<view class=" fonweight xiaohei" style="font-size: 44rpx;">{{item.jb_num}}</view>
							</view>
							<view class="xiaohei strongtext margin_top2">售价{{item.price}}</view>
						</view>
					</view>
				</view>
				<view class="bigbtn margin_top6" @click="chongzhi()">立即充值</view>
			</view>
		</view>
		<view class="mainpadding ffffff radius margin_top">
			<u-tabs :list="list1" lineColor="#333333" :scrollable="false" @click="changetab" :activeStyle="{
				    color: '#333333',
				    fontWeight: 'bold',
				    transform: 'scale(1.05)'
				}" :inactiveStyle="{
				            color: '#999999',
							fontWeight: '500',
				            transform: 'scale(1)'
				        }" itemStyle="padding-left: 16px; padding-right: 16px; height: 44px;"></u-tabs>
			<view class="xiahuaxian margin_top flexbetween" v-for="item in list.data" :key="item.id">
				<view class="">
					<view class="strongtext xiaohui">{{item.createtime_text}}</view>
					<view class="ershiba xiaohei fonweight margin_top2">{{item.memo}}</view>
				</view>
				<view class="flexleft">
					<view class="bigtext xiaohei fonweight ">{{item.money}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				list1: [{
						name: '获取记录',
						value: 1,
					},
					{
						name: '支出记录',
						value: 2,
					}
				],
				resultcode: 1,
				jbItemList:[],
				jb_item_id:"",
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				userInfo:{},
				payprice:"",
				pageShow:false,
				product_id:"",
				isSH:true
			}
		},
		onLoad() {
			this.jbItem()
			this.getsystem()
		},
		onShow() {
			this.userinfomsg()
			this.init()
		},
		methods: {
			getsystem() {
				let system = uni.getSystemInfoSync()
				let version_code = system.appVersionCode
				let platform = system.platform
				console.log(version_code,platform);
				httpRequest.request('/api/index/checkApply', 'GET', {
					platform,
					version_code
				}).then(res => {
					console.log(version_code,platform,res);
					this.isSH = res.data
				})
			},
			chongzhi(){
				if(this.jb_item_id==""){
					httpRequest.toast("请选择充值项")
					return false
				}
				let data = {
					price:this.payprice,
					jb_item_id:this.jb_item_id,
					product_id:this.product_id
				}
				uni.navigateTo({
					url:"/pages_mypage/lijicz?msg="+encodeURIComponent(JSON.stringify(data))
				})
			},
			userinfomsg() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.userInfo = res.data
					this.pageShow = true
				})
			},
			jbItem() {
				httpRequest.request('/api/Rechargecl/jbItem', 'GET', {
				}).then(res => {
					this.jbItemList = res.data
				})
			},
			init(isPage, page) {
				let _this = this
				let url = "/api/user/userJbLog"
				let data = {
					page: page || 1,
					limit: _this.limit,
					type: this.resultcode
				}
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			tztx(){
				uni.navigateTo({
					url:'/pages_mypage/tixian'
				})
			},
			changetab(e) {
				this.resultcode = e.value
				this.init()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.borders {
		border:5rpx solid #2261ff;
		border-radius: 10rpx;
	}
	.border {
		border:5rpx solid #fff;
		border-radius: 10rpx;
	}
	.jinbi {
		width: 32rpx;
		height: 32rpx;
	}

	.baibtn1 {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #7DA2FF;
		width: 154rpx;
		height: 64rpx;
		background: #FFFFFF;
		border-radius: 32rpx;
	}

	.lanbox {
		padding: 42rpx 30rpx;
		background: linear-gradient(90deg, #2361FF 0%, #8AABFF 100%);
		border-radius: 20rpx 20rpx 0rpx 0rpx;
	}

	.block {
		background: #F9F9F9;
		min-height: calc(100vh - 100rpx);
		height: auto;
	}
</style>